package cards;
import java.util.ArrayList;

import cards.Card;

public class BlackjackHand {

	private int score = 0;
	ArrayList<Card> hand = new ArrayList<Card>();
	
	public BlackjackHand() {
	}
	
	public void addCard(Card card) {
		this.hand.add(card);
		calculateScore();
	}
	
	public void addCard(Card[] cards) {
		for(int i=0; i<cards.length; i++) {
			this.hand.add(cards[i]);
		}
		calculateScore();
	}
	
	public String toString() {
		String output ="Your hand consists of: ";
		for(int i = 0; i < this.hand.size(); i++) {
			output += "\n " + this.hand.get(i).toString();
		}
		output += "\nWith a total score of: "+this.score;
		return output;
	}
	
	public int getScore() {
		return this.score;
	}
	
	public int convertRoyals(int rankValue) {
		int value = rankValue;
		if (rankValue == 11 || rankValue == 12 || rankValue == 13) {
			value = 10;
		}
		if (rankValue == 1 && score <11) {
			value = 11;			
		}
		return value;
	}
	
	public void calculateScore() {
		score = 0;
		for(int i=0; i<hand.size(); i++) {
			score += convertRoyals(((Card) hand.get(i)).getRankValue());
		}
	}
	
	public boolean containsAce() {
		boolean returnval = false;
		for (int i=0; i<this.hand.size(); i++) {
			if (this.hand.get(i).getRank() == "Ace") {
				returnval = true;
			}
		}
		return returnval;
		
	}
	
}
